#ifndef PLATFORM_LIB_H
#define PLATFORM_LIB_H

/*******************************************************************
| defines and macros (scope: module-local)
|------------------------------------------------------------------*/

#ifndef NULL
#define NULL ((void*)0)
#endif

#define ISR(FuncName) void FuncName(void) /*ISR Name*/

#define _INLINE_ inline

#define VENDOR_ID 0x00U


#define	ADC_MODULE_ID	(uint16)0X01U
#define	SPI_MODULE_ID	(uint16)0X02U
#define	GPT_MODULE_ID	(uint16)0X03U
#define	PORT_MODULE_ID	(uint16)0X04U
#define	MCU_MODULE_ID	(uint16)0X05U
#define	DIO_MODULE_ID	(uint16)0X06U
#define	PWM_MODULE_ID	(uint16)0X07U
#define	ICU_MODULE_ID	(uint16)0X08U
//#define	FLS_MODULE_ID	(uint16)0X16U
#define	FLS_MODULE_ID		92U

/*the brief of macro DEFINECRITICAL:
* define a critical environment. This macro is a redundancy
*  on the TC1767 platform.
* */
#define DEFINECRITICAL() uint32 ICR_Value

/*the brief of macro ENTER_CRITICAL:
* Disable Interrupts, enter critical region
* */
#define ENTER_CRITICAL()  ISYNC(); ICR_Value = MFCR(0xFE2C); DISABLE()

/*the brief of macro EXIT_CRITICAL:
* Enable interrupts, exit critical region
* */
#define EXIT_CRITICAL()   MTCR(0xFE2C, (ICR_Value & 0x100UL) | ((ICR_Value & 0xFFFFFEFFUL)))



/*******************************************************************************
** Macro Syntax : Mcal_EnableAllInterrupts()                                  **
**                                                                            **
** Parameters (in) :  None                                                    **
** Parameters (out):  None                                                    **
**                                                                            **
** Description    : Call to Enable All Interrupts                             **
**                                                                            **
*******************************************************************************/
#define Mcal_EnableAllInterrupts()    ENABLE()

/*******************************************************************************
** Macro Syntax : Mcal_DisableAllInterrupts()                                 **
**                                                                            **
** Parameters (in) :  None                                                    **
** Parameters (out):  None                                                    **
**                                                                            **
** Description    : Call to Disable All Interrupts                            **
**                                                                            **
*******************************************************************************/
#define Mcal_DisableAllInterrupts()    DISABLE()

/*******************************************************************************
** Macro Syntax : Mcal_SetAtomic(Address, Value, Offset, Bits)                **
**                                                                            **
** Parameters (in) :  Address: Address of the Variable to be Modified         **
**                    Value  : Value to be written                            **
**                    Offset : Bit Offset from LSB                            **
**                    Bits   : No of Bits Modified                            **
** Parameters (out):  None                                                    **
**                                                                            **
** Description    : Mcal_SetAtomic is used to write atomic instructions in    **
**                  code.The function writes the number of bits of an integer ** 
**                  value at a certain address location in memory with a ...  **
**                  bitoffset. The number of bits must be a constant value... **
**                  Note that the Address must be Word Aligned                **
**                                                                            **
*******************************************************************************/
#define Mcal_SetAtomic(Address, Value, Offset, Bits) \
            IMASKLDMST((Address),(Value),(Offset),(Bits)) 

/*******************************************************************************
** Macro Syntax : Mcal_Extract(Address, Value, Offset, Bits)                  **
**                                                                            **
** Parameters (in) :  Address: Address of the Variable to be Modified         **
**                    Value  : Value to be written                            **
**                    Offset : Bit Offset from LSB                            **
**                    Bits   : No of Bits Modified                            **
** Parameters (out):  None                                                    **
** Return          : returns the extracted specifed value                     **
** Description    : EXTRACT is used to read value from a required position    **
**                  for the desired number of bits.                           **
**                  Reads the values in a single instruction when compared    **
**                  mask and loading the same                                 **
**                                                                            **
*******************************************************************************/
#define Mcal_Extract(Value,Pos,Width) \
            (EXTRACT((Value),(Pos),(Width))) 
                                       
/*******************************************************************************
**                      Global Function Declarations                          **
*******************************************************************************/
/*******************************************************************************
** Syntax : void Mcal_ResetENDINIT(void)                                      **
**                                                                            **
** Service ID:  None                                                          **
**                                                                            **
** Sync/Async:  Synchronous                                                   **
**                                                                            **
** Reentrancy:  Non reentrant                                                 **
**                                                                            **
** Parameters (in) :  None                                                    **
**                                                                            **
** Parameters (out):  None                                                    **
**                                                                            **
** Return value    :  None                                                    **
**                                                                            **
** Description : Clears the ENDINIT bit in the                                **
**               WDT_CON0 register in order to disable the                    **
**               write-protection for registers protected                     **
**               via the EndInit feature (ie. WDT_CON1, BTV,                  **
**               BIV, ISP, mod_CLC).                                          **
**                                                                            **
*******************************************************************************/
void Mcal_ResetENDINIT(void);

/*******************************************************************************
** Syntax : Mcal_SetENDINIT(void)                                             **
**                                                                            **
** Service ID:  None                                                          **
**                                                                            **
** Sync/Async:  Synchronous                                                   **
**                                                                            **
** Reentrancy:  Non reentrant                                                 **
**                                                                            **
** Parameters (in) :  None                                                    **
**                                                                            **
** Parameters (out):  None                                                    **
**                                                                            **
** Return value    :  None                                                    **
**                                                                            **
** Description :      Bit ENDINIT in WDTCON0 is set                           **
**                    description: Clears the ENDINIT bit in the              **
**                    WDT_CON0 register in order to disable the               **
**                    write-protection for registers protected                **
**                    via the EndInit feature (ie. WDT_CON1, BTV,             **
**                    BIV, ISP, mod_CLC).                                     **
**                                                                            **
*******************************************************************************/
void Mcal_SetENDINIT(void);


#endif /* PLATFORM_LIB_H  */

